<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册将数据存储到localstorage</title>
    <style>
        .regist {
            width: 400px;
            height: 400px;
            margin: 100px auto;
            box-shadow: 0 0 2px 1px rgb(0, 0, 0, 20%);
        }

        input {
            width: 60%;
            height: 40px;
            border-radius: 10px;
            outline: none;
            text-indent: 1em;
            margin-top: 50px;
            margin-left: 20%;
        }

        button {
            width: 200px;
            height: 50px;
            background-color: #e2a7a7;
            margin: 60px 0px 0px 90px;
            border-radius: 20px;
            outline: none;
            border: none;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <div class="regist">
        <input class="box1" value="" placeholder="username:" type="text" />
        <input class="box2" value placeholder="password:" type="text" />
        <button>注册</button>
    </div>
    <script>
        let button = document.querySelector('button');
        let ipt1 = document.querySelector('.box1')
        let ipt2 = document.querySelector('.box2')
        // let arr = '1212'
        let arr = []
        function set(name, value) {
            localStorage.setItem(name, JSON.stringify(arr));
        }
        function get(name) {
           return JSON.parse(localStorage.getItem(name))
        }
        
        button.onclick = function () {
            // let result = get('name')
            // console.log(result);
            // ipt1.value = result
            arr.push(ipt1.value, ipt2.value);
            set('name',arr);
            // console.log(arr)
            get()
            // console.log(arr);
            ipt1.value = ''
            ipt2.value = '';
            let result = get('name');
            console.log(result)
            for(let i = 0; i< result.length; i++){
                ipt1.value = result[0];
                ipt2.value = result[1];
                console.log(result[0])
            }
            // ipt1.value = get('name');
            // ipt2.value = get('name');
            // console.log(result)
        }
    </script>
</body>

</html>